<template>
  <div class="rzgl-main">
    <ComTable :tableimg="tableimg" :tabletext="tabletext" :isleft="isleft" :istree="istree" :activedata='leftdata'
      :issearchbtn="issearchbtn" :searchbtn="searchbtn" :istablerightbtn="istablerightbtn"
      :tablerightbtn="tablerightbtn" :istablecolbtn="istablecolbtn" :tablecolbtn="tablecolbtn"
      :tablerightfrom="tablerightfrom" :tablerightfromvalue="tablerightfromvalue" :tableData="tableData" />
  </div>

  <Eldioa headtext="编辑用户" :dialogVisible="editdialogVisible" @eddialogVisible="updateDialogVisible" :elwidth="746"
    :elheight="475">
    <template #dialogbody>
      <el-form :model="editform" :rules="editformrules" ref="editformRef" label-position="top">
        <el-row justify="space-between">
          <el-col :span="11">
            <el-form-item label="用户名:" prop="name">
              <el-input v-model="editform.name" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="真实姓名:" prop="name">
              <el-input v-model="editform.name" />
            </el-form-item>
          </el-col>
        </el-row>
        <!--  -->
        <el-row justify="space-between">
          <el-col :span="11">
            <el-form-item label="密码:" prop="name">
              <el-input v-model="editform.name" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="角色:" prop="name">
              <el-input v-model="editform.name" />
            </el-form-item>
          </el-col>
        </el-row>
        <!--  -->
        <el-row justify="space-between">
          <el-col :span="11">
            <el-form-item label="状态:" prop="name">
              <el-input v-model="editform.name" />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="11">
            <el-form-item label="角色:">
              <el-input v-model="editform.name" />
            </el-form-item>
          </el-col> -->
        </el-row>
        <!--  -->


        <el-form-item label="备注:">
          <el-input v-model="editform.name" type="textarea" :autosize="{ minRows: 2, maxRows: 4 }" />
        </el-form-item>
        <!--  -->
        <div class="dialog-footer" style="text-align: right;">
          <el-button type="primary" style="background: rgba(4, 134, 254, 1);"
            @click="editsub(editformRef)">确认</el-button>
          <el-button
            style="background: transparent;border:1px solid rgba(89, 175, 249, 0.70);color:rgba(1, 194, 255, 1)">
            取消
          </el-button>
        </div>
      </el-form>
    </template>

  </Eldioa>
</template>

<script setup>
import { ref, provide, onMounted } from 'vue'
import { getuserlist, getfilesTree } from '@/api'
import ComTable from '@/components/table/index.vue'
import tableImgSrc from '@/assets/img/components/headicon.png'
import Eldioa from '@/components/eldioa/index.vue'

// 弹窗名称和icon
const tableimg = ref(tableImgSrc)
const tabletext = ref('文件操作')

const editdialogVisible = ref(false)

const updateDialogVisible = (newValue) => {
  editdialogVisible.value = newValue
}

const editformRef = ref()
const editform = ref({})
const editformrules = ref({
  name: [
    { required: true, message: 'Please input Activity name', trigger: 'blur' },

  ],
})


const editsub = async (formEl) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {

    if (valid) {
      console.log('submit!')
    } else {
      console.log('error submit!', fields)
    }
  })
}




/* 
左侧
isleft 是否显示 左侧数据
istree  是否显示 树形结构
leftdata  左侧数据
btnactivindex  点击之后的数据
*/
const istree = ref(true)
const isleft = ref(true)
const leftdata = ref([])


const getfilesTreeapi = async () => {

  // let res = await getfilesTree()
  // if (res.code == 200) {
  //   leftdata.value = res.data
  // }
  leftdata.value = [
    {
      id: 1,
      label: 'HSG医学知识库',
      children: [
        {
          id: 2,
          label: '伤员病案库',
          children: [],
        },
        {
          id: 3,
          label: '专家信息库',
          children: [],
        },
        {
          id: 4,
          label: '组室分类库',
          children: [],
        },
        {
          id: 5,
          label: '物资调配库',
          children: [],
        },
        {
          id: 6,
          label: 'HSG事件实例库',
          children: [],
        },
        {
          id: 7,
          label: '知识资源库',
          children: [],
        },
      ],
    },
    {
      id: 8,
      label: 'SWSG事件实例库',
      children: [
        {
          id: 9,
          label: '伤员病案库',
          children: [],
        },
        {
          id: 10,
          label: '专家信息库',
          children: [],
        },
        {
          id: 11,
          label: '组室分类库',
          children: [],
        },
        {
          id: 12,
          label: '物资调配库',
          children: [],
        },
        {
          id: 13,
          label: 'HSG事件实例库',
          children: [],
        },
        {
          id: 14,
          label: '知识资源库',
          children: [],
        },
      ],
    },
  ]
}

const btnactivindex = (data) => {
  console.log('sadadasda', data)
}


provide('btnactivindex', btnactivindex)
/* 
右侧
tablerightfrom 表单数据
tablerightfromvalue 动态表单属性(查询表单)

searchbtnfun  右侧头部查询按钮点击事件回调
issearchbtn  是否显示右侧头部查询按钮
searchbtn  右侧头部按钮数据

istablerightbtn  是否显示最右侧头部按钮
tablerightbtn  最右侧头部按钮数据

istablecolbtn  是否显示表格列按钮
tablecolbtn  表格列按钮数据
untablecolbtn 表格列按钮数据回调

tableData 表格数据
pageChange 分页改变
pageSizeChange 每页条数改变
*/

const searchbtnfun = (data) => {
  console.log('searchbtnfun', data)
}
provide('searchbtnfun', searchbtnfun)

// 右侧头部表单，动态按钮
const issearchbtn = ref(true)

const searchbtn = ref([
  {
    name: '检索',
    type: 'primary'
  },
  {
    name: '重置',
    type: ''
  }
])

const tablerightbtn = ref([])


const istablerightbtn = ref(false)

const istablecolbtn = ref(true)

const tablecolbtn = ref([
  {
    name: '编辑',
    type: 'primary',
    islink: true
  },
  {
    name: '删除',
    type: 'danger',
    islink: true
  }
])

const untablecolbtn = (data, row) => {
  console.log('单行表格数据', data, row)
  switch (data.name) {
    case '编辑':
      editdialogVisible.value = true
      break;
  }
}
provide('untablecolbtn', untablecolbtn)



const tablerightfrom = ref({
  input: '',
  select: '',

})

const tablerightfromvalue = ref([
  {
    type: 'input',
    value: 'input',
    name: '事件名称',
    placeholder: '请输入内容'
  },
  {
    type: 'select',
    value: 'select',
    name: '事件等级',
    placeholder: '请选择',
    options: [
      {
        value: 'option1',
        label: '选项1'
      },
      {
        value: 'option2',
        label: '选项2'
      },
      {
        value: 'option3',
        label: '选项3'
      }
    ]
  },
  {
    type: 'times',
    value: 'time',
    name: '发生时间',
    placeholder: '请输入内容'
  },
])

// 表格
const tableData = ref()

const SelectionChange = (data) => {
  console.log('change多选', data)
}
provide('SelectionChange', SelectionChange)

// 分页
const pageChange = async (page) => {
  const { data } = await getuserlist({ page, pageSize: tableData.value.pageSize });
  tableData.value = {
    tablename: tabletext.value,
    ...data
  };
}
const pageSizeChange = async (pageSize) => {
  const { data } = await getuserlist({ page: 1, pageSize });
  tableData.value = {
    tablename: tabletext.value,
    ...data
  };
}

provide('handlePageChange', pageChange)
provide('handlePageSizeChange', pageSizeChange)


const getuserlistapi = async () => {
  // const { data } = await getuserlist({ page: 1, pageSize: 15 })
  // tableData.value = {
  //   tablename: tabletext.value,
  //   ...data
  // }
}

onMounted(async () => {

  getuserlistapi()
  getfilesTreeapi()
})

</script>

<style lang="less" scoped>
:deep(.el-form-item__label) {
  color: #fff;
}
</style>